//
//  HomeSectionHeaderView.m
//  LingQian
//
//  Created by xieyingze on 2018/1/21.
//  Copyright © 2018年 xieyingze. All rights reserved.
//

#import "HomeHeaderView.h"

@interface HomeHeaderView()

@property (nonatomic, strong) UIView *mainView;

@property (nonatomic, strong) BaseLabel *earningLabel;
@property (nonatomic, strong) BaseImageView *headerImageView;

@end

@implementation HomeHeaderView


#pragma mark - init

- (void)initData {
    self.backgroundColor = kCOLOR_clear;
}

- (void)initSubViews {
    [self addSubview:self.mainView];
}

- (void)autoLayoutSubViews {
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
}

- (void)bindViewModel {
    @weakify(self);
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        @strongify(self);
        [self.earningLabel setAnimationWithJumpNuberFormNumber:0.00 toNumber:1.88];
    });
}

#pragma mark - method


#pragma makr - Event


#pragma mark - Setter

- (void)setOffset:(CGFloat)offset {
    if (offset <=0) {
        self.mainView.backgroundColor = [kCOLOR_tableView colorWithAlphaComponent:0];
    } else {
        CGFloat alpha = offset >= 120 ? 0.9 : (offset/120) * 0.9;
        self.mainView.backgroundColor = [kCOLOR_tableView colorWithAlphaComponent:alpha];
    }
}

- (void)setViewModel:(HomeViewModel *)viewModel {
    _viewModel = viewModel;
    [self refreshUI];
}

- (void)refreshUI {
    self.earningLabel.textColor = KCOLOR_mainColor;
    [self.earningLabel setViewShadow:[KCOLOR_mainColor colorWithAlphaComponent:0.6] offset:CGSizeMake(0, 0) radius:kUI_ShawRadius/5];
}

#pragma mark - Getter

- (UIView *)mainView {
    if (!_mainView) {
        _mainView = [UIView new];
        _mainView.backgroundColor = kCOLOR_tableView;
        
        BaseLabel *dateLabel = [BaseLabel new];
        [dateLabel setLabelStyle:@"1月21日 | 今日收益" textColor:KCOLOR_lightFont textFont:kFONT_mainFont(10) texrAlignment:NSTextAlignmentLeft];
        [_mainView addSubview:dateLabel];
        [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@20);
            make.top.equalTo(@10);
            make.height.equalTo(@10);
        }];
        
        BaseLabel *earningLabel = [BaseLabel new];
        earningLabel.backgroundColor = kCOLOR_clear;
        [earningLabel setLabelStyle:@"1.88" textColor:KCOLOR_mainColor textFont:kFONT_mainBoldFont(30) texrAlignment:NSTextAlignmentLeft];
        self.earningLabel = earningLabel;
        [_mainView addSubview:earningLabel];
        [earningLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(dateLabel.mas_bottom).offset(10);
            make.left.equalTo(dateLabel);
            make.height.equalTo(@30);
        }];
        
        BaseImageView *headerImageView = [BaseImageView new];
        headerImageView.layer.cornerRadius = 15;
        headerImageView.layer.masksToBounds = YES;
        headerImageView.imageName = @"home_header";
        self.headerImageView = headerImageView;
        [_mainView addSubview:headerImageView];
        [headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-20);
            make.centerY.equalTo(earningLabel);
            make.width.height.equalTo(@30);
        }];
    }
    return _mainView;
}

@end
